﻿@inject IStringLocalizer<BootstrapBlazor.Shared.Samples.PopoverConfirms> Localizer

<ValidateForm Model="@Model" OnValidSubmit="OnValidSubmit" OnInvalidSubmit="OnInValidSubmit">
    <div class="row g-3 form-inline">
        <div class="col-12">
            <BootstrapInput @bind-Value="@Model.Name" />
        </div>
        <div class="col-12">
            <BootstrapInput @bind-Value="@Model.Address" />
        </div>
        <div class="col-12">
            <PopConfirmButton Placement="Placement.Top"
                              Color="Color.Primary"
                              ConfirmIcon="fa-solid fa-triangle-exclamation text-info"
                              ConfirmButtonColor="Color.Success"
                              Text="@Localizer["PopoverConfirmsFormSubmitFormText"]"
                              Content="@Localizer["PopoverConfirmsFormSubmitFormContent"]"
                              Icon="fa-solid fa-floppy-disk fa-fw"
                              ButtonType="ButtonType.Submit"
                              IsAsync="true"
                              OnConfirm="OnAsyncSubmit" />
        </div>
    </div>
</ValidateForm>
<ConsoleLogger @ref="Logger" class="mt-3" />

@code {
    [NotNull]
    private Foo? Model { get; set; }

    [NotNull]
    private ConsoleLogger? Logger { get; set; }

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Model = new() { Name = "Name", Education = EnumEducation.Primary, DateTime = DateTime.Now };
    }

    private async Task OnAsyncSubmit()
    {
        Logger.Log("异步提交");
        await Task.Delay(3000);
    }

    private async Task OnValidSubmit(EditContext context)
    {
        await Task.Delay(3000);
        Logger.Log("数据合规");
    }

    private Task OnInValidSubmit(EditContext context)
    {
        Logger.Log("数据非法");
        return Task.CompletedTask;
    }
}
